<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
	</head>

	<body style="padding: 0px;">
		<div id="toolbar" class="receipts_toolbar_style"></div>
		<form id="ff">
			<table id="table" class="displaytable" cellpadding="6" style="padding: 20px;">
				<tr>
					<td width="20%">
						<h id="star">*</h> 租户姓名</td>
					<td width="10%">
						<input type="text" style="width: 100%;" name="TENANT_NAME" id="input_TENANT_NAME" class="easyui-combobox" data-options="required:true" />
					</td>
					<td width="20%">
						<h id="star">*</h> 商品名称</td>
					<td width="10%">
						<input type="text" style="width: 100%;" name="GOODS_NAME" id="input_GOODS_NAME" class="easyui-textbox" data-options="required:true" />
					</td>
					<td width="20%">
						<h id="star">*</h> 仓库名称</td>
					<td width="10%">
						<input type="text" style="width: 100%;" name="STOREHOUSE_NAME" id="input_STOREHOUSE_NAME" class="easyui-combobox" data-options="required:true" />
					</td>
				</tr>
				<tr>
					<!--<td>
						<h id="star">*</h> 入库时间</td>
					<td width="10%">
						<input type="text" style="width: 100%;" name="IN_DATE" id="input_IN_DATE" class="easyui-datebox" data-options="required:true" />
					</td>
					<td>
						<h id="star">*</h> 预存时间</td>
					<td >
						<input type="text" style="width: 100%;" name="EXT_DATE" id="input_EXT_DATE" class="easyui-datebox" data-options="required:true" />
					</td>-->
					<td>
						<h id="star">*</h> 入库类型</td>
					<td>
						<input type="text" style="width: 100%;" name="TYPE" id="input_TYPE" class="easyui-combobox" data-options="required:true" />
					</td>
					<td>
						<h id="star">*</h> 规格</td>
					<td>
						<input type="text" style="width: 100%;" name="SPEC" id="input_SPEC" class="easyui-textbox" data-options="required:true" />
					</td>
					<td>
						<h id="star">*</h> 单位</td>
					<td>
						<input type="text" style="width: 100%;" name="UNIT" id="input_UNIT" class="easyui-textbox" data-options="required:true" />
					</td>
				</tr>
				<tr>

					<td>
						<h id="star">*</h> 数量</td>
					<td>
						<input type="text" style="width: 100%;" name="AMOUNT" id="input_AMOUNT" class="easyui-numberbox" data-options="required:true" />
					</td>

					<td>
						<h id="star">*</h> 收费类型</td>
					<td>
						<input type="text" style="width: 100%;" name="CHARGE_NAME" id="input_CHARGE_NAME" class="easyui-combobox" data-options="required:true" />
					</td>
					<td>
						<h id="star">*</h> 单价/元</td>
					<td>
						<input type="text" style="width: 100%;" name="PRICERANGE" id="input_PRICERANGE" class="easyui-numberbox" data-options="required:true,disabled:true" />
					</td>
				</tr>
				<tr>
					<td>&nbsp;合伙人1</td>
					<td>
						<input type="text" style="width: 100%;" name="PARTNER1" id="input_PARTNER1" class="easyui-combobox" />
					</td>
					<td>&nbsp;合伙人2</td>
					<td>
						<input type="text" style="width: 100%;" name="PARTNER2" id="input_PARTNER2" class="easyui-combobox" />
					</td>
					<td>&nbsp;合伙人3</td>
					<td>
						<input type="text" style="width: 100%;" name="PARTNER3" id="input_PARTNER3" class="easyui-combobox" />
					</td>
				</tr>
				<tr>

					<!--<td>
						<h id="star">*</h> 搬运费用(元)</td>
					<td >
						<input type="text" style="width: 100%;" name="HAND_FEE" id="input_HAND_FEE" class="easyui-numberbox feeinput" data-options="precision:2" />
					</td>-->
					<td>
						其他费用(元)</td>
					<td>
						<input type="text" style="width: 100%;" name="OTHRE_FEE" id="input_OTHRE_FEE" class="easyui-numberbox feeinput" data-options="precision:2" />
					</td>
					<td>
						<h id="star">*</h> 入库时间</td>
					<td width="10%">
						<input type="text" style="width: 100%;" name="IN_DATE" id="input_IN_DATE" class="easyui-datebox" />
					</td>
					<!-- <td >
						<h id="star">*</h> 应收费用(元)</td>
					<td >
						<input type="text" style="width: 100%;" name="SUM" id="input_SUM" class="easyui-numberbox" data-options="required:true,readonly:true,precision:2" />
					</td>
					<td >
						<h id="star">*</h> 实收费用</td>
					<td >
						<input type="text" style="width: 100%;" name="REAL_SUM" id="input_REAL_SUM" class="easyui-numberbox" data-options="required:true,precision:2" />
					</td> -->
				</tr>
				<tr>

				</tr>
			</table>
			<table>
				<tr style="display: none;">
					<td>商品ID</td>
					<td>
						<input type="text" style="width: 100%;" name="GOODS_ID" id="input_GOODS_ID" class="easyui-textbox" />
					</td>
					<td>仓库编码</td>
					<td>
						<input type="text" style="width: 100%;" name="STOREHOUSE_ID" id="input_STOREHOUSE_ID" class="easyui-textbox" />
					</td>
					<td>租户ID</td>
					<td>
						<input type="text" style="width: 100%;" name="TENANT_ID" id="input_TENANT_ID" class="easyui-textbox" />
					</td>

					<td>
						<h id="star">*</h> 收费标准ID</td>
					<td>
						<input type="text" style="width: 100%;" name="CHARGETYPE_ID" id="input_CHARGETYPE_ID" class="easyui-textbox" />
					</td>
				</tr>
				<tr class="hiddentr">
					<td>合伙人1ID</td>
					<td>
						<input type="text" style="width: 100%;" name="PARTNER1_ID" id="input_PARTNER1_ID" class="easyui-textbox" />
					</td>
					<td>合伙人2ID</td>
					<td>
						<input type="text" style="width: 100%;" name="PARTNER2_ID" id="input_PARTNER2_ID" class="easyui-textbox" />
					</td>
					<td>合伙人3ID</td>
					<td>
						<input type="text" style="width: 100%;" name="PARTNER3_ID" id="input_PARTNER3_ID" class="easyui-textbox" />
					</td>
					<td>当前库存量</td>
					<td>
						<input type="text" style="width: 100%;" name="CURR_AMOUNT" id="input_CURR_AMOUNT" class="easyui-textbox" />
					</td>

				</tr>
			</table>
			<div id="dlg" class="easyui-dialog" closed="true" style="width:560px;height:400px;padding:10px">
				<iframe id="ifrmEdit" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>
			</div>
			<div id="new_footer"></div>
		</form>
		<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../../JS/common.js"></script>
		<script type="text/javascript" src="../../../JS/FrozenShareFunction/FrozenShare.js"></script>
		<script type="text/javascript" src="../../../JS/MarketShareFunction/DialogShareFunction.js"></script>
	</body>
	<script type="text/javascript">
		var content;
		var id = getID();
		var currid;
		var MaxPage;
		var MinPage;
		var currPage;
		var isVerify;
		var AddDialog;
		var type;
		var displayInDate;
		var receipts_type = RECEIPT_UNVERIFY_SYMBOL + RECEIPT_PRINT_SYMBOL + RECEIPT_EXPORT_SYMBOL;
		receipts_type += RECEIPT_SAVE_SYMBOL + RECEIPT_ADD_SYMBOL + RECEIPT_DELETE_SYMBOL + RECEIPT_NEXT_SYMBOL + RECEIPT_FRONT_SYMBOL + RECEIPT_CHARGE_SYMBOL;
		content = AddReceiptsToolBar(receipts_type, "");
		$("#toolbar").append(content);
		addDialogFooter($("#new_footer"));

		getPageMaxAndMin();
		initCombobox();
		displayInDate = getModiDateAuth();

		$(document).ready(function() {
			///增加了对入库时间的处理审核
			var tmpDate = new Date();
			var inDate = tmpDate.toLocaleDateString();
			$('#input_IN_DATE').datebox('setValue', inDate);
			if(displayInDate) {
				$("#input_IN_DATE").datebox('readonly', false);
			} else {
				$("#input_IN_DATE").datebox('readonly', true);
			}
			if(id != AddFlag) {
				currid = id;
				var _url = RemoteLinkAddress + '/frozen/inorder/findbyid.do?ID=' + currid;
				getRemoteData(_url);
			} else {
				currid = AddFlag;
			}

		})

		//新建按钮
		function newdata() {
			$("#verifydisplay").empty(); //去掉审核或者未审核的图片
			isVerify = 0; //将状态改为未审核
			currid = AddFlag;
			resetData();
		}

		//上一页按钮
		function frontpage() {
			if(currid == AddFlag) {
				currid = currPage;
			}
			if(currid <= MinPage) {
				$.messager.alert("消息", "没有上张");
				return;
			}
			var _url = RemoteLinkAddress + '/frozen/inorder/pre.do?ID=' + currid;
			getRemoteData(_url);
		}

		//下一页按钮
		function nextpage() {
			if(currid == AddFlag) {
				currid = currPage;
			}
			if(currid >= MaxPage) {
				$.messager.alert("消息", "没有下张");
				return;
			}
			var _url = RemoteLinkAddress + '/frozen/inorder/next.do?ID=' + currid;
			getRemoteData(_url);
		}

		//保存按钮
		function save() {
			var isValid = $("#fm").form('validate');
			if(!isValid) {
				$.messager.alert("警告", "有必填项没有填写");
				return;
			}
			var _url;

			if(currid == AddFlag) {
				_url = RemoteLinkAddress + "/frozen/inorder/save.do";
			} else {
				if(type == "1") {
					$.messager.alert("消息", "转入库记录不能修改!");
					return;
				}
				if(isVerify == 1) {
					$.messager.alert("警告", "表单已审核不能修改!");
					return;
				}
				_url = RemoteLinkAddress + "/frozen/inorder/update.do";
			}
			saveData(_url);
		}

		//删除按钮
		function deletedata() {
			if(currid == AddFlag) {
				$.messager.alert("警告", "该页面为新增页面，无法删除");
				return;
			}
			if(isVerify == 1) {
				$.messager.alert("警告", "表单已审核，无法删除");
				return;
			}
			$.messager.confirm("确认", "是否删除", function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/frozen/inorder/delete.do", {
						"ID": currid,
					}, function(result) {
						if(result.msg == "success") {
							$.messager.alert({
								title: '成功',
								msg: '删除成功!'
							});
							reflashList();
							nextpage();
						} else {
							$.messager.alert({
								title: 'Error',
								msg: result.msg
							});
						}
					}, 'json');
				}
			});
		}

		//收费
		function charge() {
			if(currid == AddFlag) {
				$.messager.alert("警告", "当前是新增页面，不能执行！");
				return;
			}
			var pLocation = "UI/FrozenCave/TenantCharge/TenantChargeAdd.html?type=in&id=" + currid;
			$("#ifrmEdit").attr("src", pLocation);
			constructDialog($("#dlg"), "收费", ChargeDialogWidth, ChargeDialogHeight);
			AddDialog.dialog('open');
		}

		//审核按钮
		function verifydata() {
			if(currid == AddFlag) {
				$.messager.alert("警告", "该页面为新增页面，不能执行");
				return;
			}
			if(isVerify == 1) {
				$.messager.alert("警告", "表单已审核，无须再审");
				return;
			}
			$.messager.confirm("确认", "是否审核", function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/frozen/inorder/verify.do", {
						"ID": currid,
					}, function(result) {
						if(result.msg == "success") {
							$.messager.alert({
								title: '成功',
								msg: '审核成功!'
							});
							verifyStatus_Market(1, true);
							isVerify = 1;
							reflashList();
						} else {
							$.messager.alert({
								title: 'Error',
								msg: result.msg
							});
						}
					}, 'json');
				}
			});
		}

		//弃审按钮
		function unverifydata() {
			if(currid == AddFlag) {
				$.messager.alert("警告", "该页面为新增页面，不能执行");
				return;
			}
			if(isVerify == 0) {
				$.messager.alert("警告", "表单已弃审，无须再审");
				return;
			}
			$.messager.confirm('Confirm', '是否弃审', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/frozen/inorder/unverify.do", {
							"ID": currid,
						},
						function(result) {
							if(result.msg == "success") {
								$.messager.alert({
									title: '成功',
									msg: '弃审成功!'
								});
								verifyStatus_Market(0, true);
								isVerify = 0;
								reflashList();
							} else {
								$.messager.alert({
									title: 'Error',
									msg: result.msg
								});
							}
						},
						'json');
				}
			});
		}

		function print() { //打印
			if(currid == AddFlag) {
				$.messager.alert('警示', "当前页面为新增页面，不可打印！");
				return;
			}
			if(currid == AddFlag || isVerify != 1) {
				$.messager.alert('警示', "该单据未审核，不可以打印！");
				return;
			}
			var pLocation = "LeasingOperationPrintInStorage.html?id=" + currPage
			window.open(pLocation);
		}

		//导出
		function exportExcel() {
			if(currid == AddFlag) {
				$.messager.alert("警告", "该订单为新增订单，无法导出Excel！");
				return;
			}
			$.messager.confirm("提示", "确认导出Excel表格吗？", function(r) {
				if(r) {
					$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
						type: "get",
						data: {
							"ID": currid
						},
						url: RemoteLinkAddress + "/frozen/inorder/excelorder.do",
						dataType: "json", //服务器返回的数据类型
						success: function(result) {
							window.location.href = result.path;
						}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
						error: function(xhr, status, error) {
							$.messager.alert("错误", "请求失败!");
						}
					});
				}
			});
		}

		//提交数据
		function saveData(_url) {
			lockButton("lock");
			var _data = submitDialogData();
			if(_data.PARTNER1_ID == "") {
				_data.PARTNER1_ID = 0;
			}
			if(_data.PARTNER2_ID == "") {
				_data.PARTNER2_ID = 0;
			}
			if(_data.PARTNER3_ID == "") {
				_data.PARTNER3_ID = 0;
			}
			if(currid != AddFlag) {
				_data.ID = currid;
			}
			$.ajax({
				dataType: 'JSON',
				url: _url,
				data: _data,
				type: "post",
				success: function(result) {
					lockButton("unlock");
					if(result.msg.search("success") > -1) {
						$.messager.alert("消息", "保存成功");
						reflashList();
						var parentLocation;
						parentLocation = searchParent("LeasingOperationList.html");
						parentLocation.dialogClose();
					} else {
						$.messager.alert("提示", "保存失败");
					}
				},
				error: function(result) {
					$.messager.alert("错误", "保存失败");
				}
			});
		}

		//刷新list页面
		function reflashList() {
			var parentLocation;
			parentLocation = searchParent("LeasingOperationList.html");
			parentLocation.reloadData();
		}

		function getRemoteData(_url) {
			$.ajax({
				type: "get",
				url: _url,
				dataType: "json",
				success: function(result) {
					if(result != null) {
						if(result.msg === "nextnull") {
							$.messager.alert("消息", "没有下张");
							return;
						}
						if(result.msg === "prenull") {
							$.messager.alert("消息", "没有上张");
							return;
						}
						isVerify = result.ISVERIFY;
						currid = result.ID;
						currPage = result.ID;
						type = result.TYPE;
						getDialogData(result);
						verifyStatus_Market(isVerify, true);
					}
				}
			});
		}

		//判断数据的完整性
		function isTrueData() {
			var tip = true;
			var _name;
			$("#table input[name]").each(function(index) {
				_name = $(this).attr("name");
				if(_name === "PARTNER1" || _name === "PARTNER2" || _name === "PARTNER3") {
					return;
				}
				if($(this).val().trim().length == 0) {
					tip = false;
					return;
				}
			});
			return tip;
		}

		//获取最大最小页
		function getPageMaxAndMin() {
			var _url = RemoteLinkAddress + "/frozen/inorder/getmaxminid.do";
			$.ajax({
				type: "get",
				url: _url,
				dataType: "json",
				success: function(result) {
					if(result != null) {
						MaxPage = result.MAXID;
						MinPage = result.MINID;
						currPage = MinPage + 1;
					}
				},
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}

		//初始化combobox
		function initCombobox() {
			//构建租户姓名
			createTenantCombobox();

			//构建库房名称的combobox
			createShoreHouseCombobox();

			//构建合伙人
			$("#input_PARTNER1").combobox({
				valueField: 'TENANT_NAME',
				textField: 'TENANT_NAME',
				panelHeight: 'auto',
				mode: 'remote',
				method: 'get',
				onChange: function(newValue, oldValue) {
					if(newValue != "" && newValue != undefined) {
						var url = RemoteLinkAddress + "/frozen/tenant/findbypinyin?PINYINFIELDNAME=" + newValue.trim();
						$(this).combobox("reload", url);
					}
				},
				onSelect: function(record) {
					$("#input_PARTNER1_ID").textbox('setValue', record.ID);
				}
			});

			$("#input_PARTNER2").combobox({
				valueField: 'TENANT_NAME',
				textField: 'TENANT_NAME',
				panelHeight: 'auto',
				mode: 'remote',
				method: 'get',
				onChange: function(newValue, oldValue) {
					if(newValue != "" && newValue != undefined) {
						var url = RemoteLinkAddress + "/frozen/tenant/findbypinyin?PINYINFIELDNAME=" + newValue.trim();
						$(this).combobox("reload", url);
					}
				},
				onSelect: function(record) {
					$("#input_PARTNER2_ID").textbox('setValue', record.ID);
				}
			});

			$("#input_PARTNER3").combobox({
				valueField: 'TENANT_NAME',
				textField: 'TENANT_NAME',
				panelHeight: 'auto',
				mode: 'remote',
				method: 'get',
				onChange: function(newValue, oldValue) {
					if(newValue != "" && newValue != undefined) {
						var url = RemoteLinkAddress + "/frozen/tenant/findbypinyin?PINYINFIELDNAME=" + newValue.trim();
						$(this).combobox("reload", url);
					}
				},
				onSelect: function(record) {
					$("#input_PARTNER3_ID").textbox('setValue', record.ID);
				}
			});

			//			//构建商品
			createGoodCombobox();

			//收费类型
			$("#input_CHARGE_NAME").combobox({
				valueField: 'CHARGE_NAME',
				textField: 'CHARGE_NAME',
				panelHeight: 'auto',
				mode: 'remote',
				method: 'get',
				onChange: function(newValue, oldValue) {
					if(newValue != "" && newValue != undefined) {
						var url = RemoteLinkAddress + "/frozen/fees/findbypinyin?PINYINFIELDNAME=" + newValue.trim();
						$(this).combobox("reload", url);
					}
				},
				onSelect: function(record) {
					$("#input_PRICERANGE").textbox('setValue', record.PRICERANGE);
					$('#input_CHARGETYPE_ID').textbox('setValue', record.CHARGETYPE_ID);
				},
			})

			//构建入库类型
			$("#input_TYPE").combobox({
				panelHeight: "50px",
				valueField: 'value',
				textField: 'text',
				data: [{
					"value": "0",
					"text": "新入库"
				}, {
					"value": "1",
					"text": "转入库"
				}]
			})
		}
	</script>

</html>